<template>
   <div class="product-con4">
     <el-card class="box-card1">
      <div class="clearfix1">
        <span><i class="iconfont icon-dingdan11"></i> 商品分类数据列表</span>
        <el-button style="float: right" type="primary" size="small">添加</el-button>
      </div>
    </el-card>

    
    <el-table :data="brandList" border style="width: 100%" class="listcc" :cell-style="{textAlign:'center'}" :header-cell-style="{'text-align':'center'}">
      <el-table-column prop="id" label="编号" width="80"></el-table-column>
      <el-table-column prop='name' label="分类名称" width="80"></el-table-column>
      <el-table-column prop='first_letter' label="品牌首字母" width="100"></el-table-column>
      <el-table-column prop="product_comment_count" label="排序" width="80"></el-table-column>
      <el-table-column label="制造商" width="100">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.show_type" :active-value="1" :inactive-value="0"></el-switch>
        </template>

      </el-table-column>
      <el-table-column label="是否显示" width="80" align="center">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.show_type" :active-value="1" :inactive-value="0"></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="相关" width="180">
          <template slot-scope="scope">
            <div>商品：{{scope.row.product_comment_count}}</div>
          </template>

      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button size="mini" type="danger"  @click="handleDelete(scope.$index, scope.row)"  >删除</el-button >
        </template>
      </el-table-column>
    </el-table> 
     <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="listQuery.pageNum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="listQuery.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>
  </div>
</template>

<script>
import {fetchbrandList} from "@/api/product.js"
export default {
    name:'brand',
    data:function(){
      return{
        brandList:[],
        listQuery:{
          pageSize:5,
          pegaNum:1
        },
        total:0,
    
      }
    },
 methods:{
    getProductList(){
      fetchbrandList(this.listQuery).then((res)=>{
        console.log(res);
        this.brandList = res.data;
        this.total=res.total;
      })
    },
    handleSizeChange(val) {
      console.log("修改页面条数的函数运行了", val);
      this.listQuery.pageSize = val;
      
      this.listQuery.pageNum = val;
      //获取数据
      this.getProductList();
    },
    handleCurrentChange(val) {
      console.log("修改当前页的页码的函数运行了", val);
      //将页码信息 保存到  listQuery
      this.listQuery.pageNum = val;
      //再次获取数据
      this.getProductList();
    },
  },
  created(){
    this.getProductList()
  },
}
</script>

<style>
.product-con4{
  margin-bottom: 100px;
}

</style>